Skip to content

fix(auth): add cross-service Drive scopes for docs and sheets tools - #432

Merged
taylorwilsdon merged 2 commits into
taylorwilsdon:mainfrom
Milofax:fix/cross-service-scopes
Feb 11, 2026
Merged

fix(auth): add cross-service Drive scopes for docs and sheets tools#432
taylorwilsdon merged 2 commits into
taylorwilsdon:mainfrom
Milofax:fix/cross-service-scopes

Conversation

@Milofax

@Milofax Milofax commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Several docs and sheets tools internally use the Google Drive API but don't receive the necessary Drive OAuth scopes when configured with --tools docs sheets (without explicitly adding drive):

  • Docs tools affected: search_docs, get_doc_content, list_docs_in_folder, export_doc_to_pdf
  • Sheets tools affected: list_spreadsheets

These tools use @require_google_service("drive", ...) internally, which calls build("drive", "v3", credentials). The credentials work because the service builder doesn't gate on --tools, but the OAuth token lacks the required Drive scopes — causing API 403 errors at runtime.

Fix

Add minimal cross-service Drive scopes to DOCS_SCOPES and SHEETS_SCOPES in auth/scopes.py:

  • docs: drive.readonly (for metadata queries) + drive.file (for PDF export)
  • sheets: drive.readonly (for spreadsheet listing)

This follows the existing pattern where SCRIPT_SCOPES (appscript) already includes DRIVE_FILE_SCOPE as a cross-service dependency (line 127).

Importantly, this does not add drive (full access) — only the minimal scopes needed. The alternative workaround of adding --tools drive exposes 14 full-access Drive tools, which is undesirable from a least-privilege perspective.

Changes

File Change
auth/scopes.py Add DRIVE_READONLY_SCOPE + DRIVE_FILE_SCOPE to DOCS_SCOPES, DRIVE_READONLY_SCOPE to SHEETS_SCOPES, and corresponding read-only variants
tests/test_scopes.py 10 unit tests verifying scope generation for docs, sheets, combined, and read-only modes

Test plan

  • All 10 new scope tests pass
  • All 74 existing unit tests still pass (84 total passed, 8 pre-existing errors in manual_test.py fixture)
  • Manual verification: --tools docs sheets (without drive) can successfully call search_docs, list_spreadsheets, export_doc_to_pdf

🤖 Generated with Claude Code

Several docs tools (search_docs, get_doc_content, list_docs_in_folder,
export_doc_to_pdf) and sheets tools (list_spreadsheets) internally use
the Google Drive API but only receive docs/sheets-specific OAuth scopes
when configured with `--tools docs sheets` (without `drive`).

This adds the minimal required Drive scopes as cross-service dependencies:
- docs: drive.readonly (metadata queries) + drive.file (PDF export)
- sheets: drive.readonly (spreadsheet listing)

This follows the existing pattern where appscript already includes
DRIVE_FILE_SCOPE for its Drive API dependency.

The alternative workaround of adding `--tools drive` exposes 14
full-access Drive tools which is undesirable from a security perspective.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@taylorwilsdon

Copy link
Copy Markdown
Owner

Hm, that's an interesting point. I think on one side, that may be concerning to users who think that they are only doing x and instead are getting a scope request that while legitimate is for y, but to your point the tools won't all work without it. I'm open to merging this, will need a ruff format but otherwise seems clean thanks!

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Milofax

Milofax commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Pushed a ruff format fix (821804c) — the DOCS_SCOPES list needed multi-line formatting.

CI shows action_required (fork PR approval needed). Once approved, all checks should pass — verified locally with ruff format --check and ruff check.

@taylorwilsdon taylorwilsdon self-assigned this Feb 11, 2026
@taylorwilsdon taylorwilsdon added the bug Something isn't working label Feb 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a runtime 403 error issue where docs and sheets tools fail when calling the Google Drive API because they lack the necessary Drive OAuth scopes. The fix adds minimal cross-service Drive scopes (drive.readonly and drive.file) to docs and sheets scope configurations, following the existing pattern used by the appscript tool.

Changes:

  • Added DRIVE_READONLY_SCOPE and DRIVE_FILE_SCOPE to DOCS_SCOPES for metadata queries and PDF export functionality
  • Added DRIVE_READONLY_SCOPE to SHEETS_SCOPES for spreadsheet listing
  • Updated read-only mode scope mappings to include DRIVE_READONLY_SCOPE for both docs and sheets
  • Added comprehensive unit tests covering scope generation for docs, sheets, combined tools, and read-only modes

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
auth/scopes.py Modified scope definitions to include necessary Drive scopes for docs and sheets tools, enabling cross-service API calls without requiring explicit --tools drive flag
tests/test_scopes.py Added 10 new unit tests to verify correct scope generation across different tool combinations and read-only mode configurations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@taylorwilsdon

Copy link
Copy Markdown
Owner

Thanks!

@taylorwilsdon
taylorwilsdon merged commit ad53deb into taylorwilsdon:main Feb 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants